/// app 应用市场
class AppMarket {
  /// 获取所有内置的应用商店
  static List<AppMarketInfo> get buildInMarketList {
    return [
      xiaoMi,
      meiZu,
      vivo,
      oppo,
      huaWei,
      zte,
      qiHoo,
      tencent,
      pp,
      wanDouJia
    ];
  }

  /// 小米
  static const xiaoMi = AppMarketInfo(
      'xiaoMi', 'com.xiaomi.market', 'com.xiaomi.market.ui.AppDetailActivity');

  /// 魅族
  static const meiZu = AppMarketInfo('meiZu', 'com.meizu.mstore',
      'com.meizu.flyme.appcenter.activitys.AppMainActivity');

  /// vivo
  static const vivo = AppMarketInfo(
      'vivo', 'com.bbk.appstore', 'com.bbk.appstore.ui.AppStoreTabActivity');

  /// oppo
  static const oppo = AppMarketInfo('oppo', 'com.oppo.market', 'a.a.a.aoz');

  /// 华为
  static const huaWei = AppMarketInfo('huaWei', 'com.huawei.appmarket',
      'com.huawei.appmarket.service.externalapi.view.ThirdApiActivity');

  /// zte
  static const zte = AppMarketInfo('zte', 'zte.com.market',
      'zte.com.market.view.zte.drain.ZtDrainTrafficActivity');

  /// 360
  static const qiHoo = AppMarketInfo('qiHoo', 'com.qihoo.appstore',
      'com.qihoo.appstore.distribute.SearchDistributionActivity');

  /// 应用宝
  static const tencent = AppMarketInfo(
      'tencent',
      'com.tencent.android.qqdownloader',
      'com.tencent.pangu.link.LinkProxyActivity');

  /// pp助手
  static const pp = AppMarketInfo(
      'pp', 'com.pp.assistant', 'com.pp.assistant.activity.MainActivity');

  /// 豌豆荚
  static const wanDouJia = AppMarketInfo('wanDouJia', 'com.wandoujia.phoenix2',
      'com.pp.assistant.activity.PPMainActivity');

  /// 获取所有内置的应用商店的包名
  static List<String> get buildInPackageNameList {
    return buildInMarketList.map((f) {
      return f.packageName;
    }).toList();
  }

  /// 通过包名获取内置应用商店
  static List<AppMarketInfo> getBuildInMarketList(List<String> packageNames) {
    List<AppMarketInfo> marketList = [];
    for (final packageName in packageNames) {
      for (final f in buildInMarketList) {
        if (f.packageName == packageName) {
          marketList.add(f);
        }
      }
    }
    return marketList;
  }

  /// 通过包名获取商店
  static AppMarketInfo? getBuildInMarket(String packageName) {
    AppMarketInfo? info;
    for (final f in buildInMarketList) {
      if (f.packageName == packageName) {
        info = f;
      }
    }
    return info;
  }
}

class AppMarketInfo {
  final String marketName;
  final String packageName;
  final String className;

  const AppMarketInfo(
    this.marketName,
    this.packageName,
    this.className,
  );
}
